﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevelopStudio.Basic;

namespace DevelopStudio.Control.Basic
{
    public partial class ChangelistPageControl : PageControl
    {
        public ChangelistInfo ChangelistInfo { get; set; }

        #region Summary Actions

        /// <summary>
        /// Add summary items for this wizard page.
        /// </summary>
        /// <remarks>Called when it is time to add Summary Actions.</remarks>
        public virtual void OnAddSummary(SummaryRequestHandler handler)
        {
            // Save the handler.
            summaryActionHandler = handler;

            // Do nothing.
        }

        private SummaryRequestHandler summaryActionHandler;

        /// <summary>
        /// Gets/Sets the message that should appear at the top of the Summary/Confirmation page.
        /// </summary>
        protected string SummaryMessage
        {
            get
            {
                // Make sure there is a handler to call.
                if (summaryActionHandler == null)
                {
                    // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                    return null;
                }

                // Call the delegate to set the message.
                return summaryActionHandler.Invoke(SummaryRequestType.GetSummaryMessage, null) as string;
            }

            set
            {
                // Make sure there is a handler to call.
                if (summaryActionHandler == null)
                {
                    // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                }

                // Call the delegate to get the message.
                summaryActionHandler.Invoke(SummaryRequestType.SetSummaryMessage, null, value);
            }
        }

        /// <summary>
        /// Gets/Sets the message shown at the bottom of the Summary page.
        /// </summary>
        protected string SummaryProceedMessage
        {
            get
            {
                // Make sure there is a handler to call.
                if (summaryActionHandler == null)
                {
                    // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                    return null;
                }

                // Call the delegate to set the message.
                return summaryActionHandler.Invoke(SummaryRequestType.GetProceedMessage, null) as string;
            }

            set
            {
                // Make sure there is a handler to call.
                if (summaryActionHandler == null)
                {
                    // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                }

                // Call the delegate to get the message.
                summaryActionHandler.Invoke(SummaryRequestType.SetProceedMessage, null, value);
            }
        }

        /// <summary>
        /// Gets/Set the message at the bottom of the Confirmation page.
        /// </summary>
        protected string ConfirmationCloseMessage
        {
            get
            {
                // Make sure there is a handler to call.
                if (summaryActionHandler == null)
                {
                    // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                    return null;
                }

                // Call the delegate to set the message.
                return summaryActionHandler.Invoke(SummaryRequestType.GetCloseMessage, null) as string;
            }

            set
            {
                // Make sure there is a handler to call.
                if (summaryActionHandler == null)
                {
                    // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                }

                // Call the delegate to get the message.
                summaryActionHandler.Invoke(SummaryRequestType.SetCloseMessage, null, value);
            }
        }

        /// <summary>
        /// Get the list of summary items.
        /// </summary>
        /// <returns>Returns the list of summary items.</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        protected IEnumerable<SmsSummaryItem> GetSummaryItems()
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to add an action.
            return summaryActionHandler.Invoke(SummaryRequestType.GetSummaryItems, null) as IEnumerable<SmsSummaryItem>;
        }

        /// <summary>
        /// Adds a new action group with the specified actionId and title.
        /// </summary>
        /// <param name="groupId">The group id.</param>
        /// <param name="title">The title.</param>
        /// <returns>Returns the summary  action group.</returns>
        protected SmsSummaryActionGroup AddActionGroup(string groupId, string title)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to add an action.
            return summaryActionHandler.Invoke(SummaryRequestType.AddGroup, groupId, title) as SmsSummaryActionGroup;
        }

        /// <summary>
        /// Adds a new action with the specified actionId, title and details to the group with the specified groupId.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <param name="title">The title.</param>
        /// <param name="details">The details.</param>
        /// <param name="groupId">The group id.</param>
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction AddAction(string actionId, string title, IEnumerable<string> details, string groupId)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to add an action.
            return summaryActionHandler.Invoke(SummaryRequestType.AddAction, actionId, title, details, groupId) as SmsSummaryAction;
        }

        /// <summary>
        /// Adds a new action with the specified actionId, title and details.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <param name="title">The title.</param>
        /// <param name="details">The details.</param>
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction AddAction(string actionId, string title, IEnumerable<string> details)
        {
            return AddAction(actionId, title, details, null);
        }

        /// <summary>
        /// Adds a new action with the specified actionId and title to the group with the specified groupId.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <param name="title">The title.</param>
        /// <param name="groupId">The group id.</param>
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction AddAction(string actionId, string title, string groupId)
        {
            return AddAction(actionId, title, null, groupId);
        }

        /// <summary>
        /// Adds a new action with the specified actionId and title.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <param name="title">The title.</param>
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction AddAction(string actionId, string title)
        {
            return AddAction(actionId, title, null, null);
        }

        /// <summary>
        /// Removes the action with the specified ID.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>Returns the summary item.</returns>
        protected SmsSummaryItem RemoveItem(string id)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to remove the action.
            return summaryActionHandler.Invoke(SummaryRequestType.RemoveItem, id) as SmsSummaryItem;
        }

        /// <summary>
        /// Replaces the action with the specified actionId, with a new action with the same actionId, but a new title and details.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <param name="title">The title.</param>
        /// <param name="details">The details.</param>
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction ReplaceAction(string actionId, string title, IEnumerable<string> details)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to replace the action.
            return summaryActionHandler.Invoke(SummaryRequestType.ReplaceAction, actionId, title, details) as SmsSummaryAction;
        }

        /// <summary>
        /// Updates the title of the action with the specified ID.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <param name="title">The title.</param>
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction UpdateAction(string actionId, string title)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to update the title of the action.
            return summaryActionHandler.Invoke(SummaryRequestType.UpdateAction, actionId, title) as SmsSummaryAction;
        }

        /// <summary>
        /// Updates the title of the group with the specified ID.
        /// </summary>
        /// <param name="groupId">The group id.</param>
        /// <param name="title">The title.</param>
        /// <returns>Returns the summary action group.</returns>
        protected SmsSummaryActionGroup UpdateGroup(string groupId, string title)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to update the title of the group.
            return summaryActionHandler.Invoke(SummaryRequestType.UpdateGroup, groupId, title) as SmsSummaryActionGroup;
        }

        /// <summary>
        /// Updates the status of the action with the specified ID.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <param name="status">The ActionStatus.</param>
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction UpdateActionStatus(string actionId, SmsSummaryAction.ActionStatus status)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to update the status of the action.
            return summaryActionHandler.Invoke(SummaryRequestType.UpdateActionStatus, actionId, status) as SmsSummaryAction;
        }

        /// <summary>
        /// Sets the details of the specified action.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction ClearActionDetails(string actionId)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to set the details of an action.
            return summaryActionHandler.Invoke(SummaryRequestType.ClearActionDetails, actionId) as SmsSummaryAction;
        }

        /// <summary>
        /// Adds a detail string to the action with the specified ID.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <param name="message">The detail message string.</param>
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction AddActionDetailMessage(string actionId, string message)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to add a detail to the action.
            return summaryActionHandler.Invoke(SummaryRequestType.AddActionDetail, actionId, message) as SmsSummaryAction;
        }

        /// <summary>
        /// Adds a warning message to the action with the specified ID.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <param name="message">The warning message string.</param>
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction AddActionWarningMessage(string actionId, string message)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to add a warning to the action.
            return summaryActionHandler.Invoke(SummaryRequestType.AddActionWarning, actionId, message) as SmsSummaryAction;
        }

        /// <summary>
        /// Adds an error message to the action with the corresponding ID.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <param name="message">The error message string.</param>  
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction AddActionErrorMessage(string actionId, string message)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to add an error to the action.
            return summaryActionHandler.Invoke(SummaryRequestType.AddActionError, actionId, message) as SmsSummaryAction;
        }

        /// <summary>
        /// Adds a correction string to the action with the specified ID.
        /// </summary>
        /// <param name="actionId">The action id.</param>
        /// <param name="message">The correction message string.</param> 
        /// <returns>Returns the summary action.</returns>
        protected SmsSummaryAction AddActionCorrectiveStepMessage(string actionId, string message)
        {
            // Make sure there is a handler to call.
            if (summaryActionHandler == null)
            {
                // Do not throw an exception so developers don't have to try/catch for PropertySheet pages.
                return null;
            }

            // Call the delegate to add a corrective step to the action.
            return summaryActionHandler.Invoke(SummaryRequestType.AddActionCorrectiveStep, actionId, message) as SmsSummaryAction;
        }

        #endregion

        public ChangelistPageControl()
        {
            InitializeComponent();
        }

        public ChangelistPageControl(ChangelistInfo changelistInfo)
        {
            InitializeComponent();
            this.ChangelistInfo = changelistInfo;
        }
    }
}
